﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using SEOBlog.Services;
using SEOBlog.Web.Models;

namespace SEOBlog.Web.Controllers
{
    public class FrontController : Controller
    {
        private PagesService _pagesService = new PagesService();

        //
        // GET: /Front/

        public ActionResult Index()
        {
            var requestedUrl = ((Route)ControllerContext.RouteData.Route).Url;

            PageViewModel pageModel;

            if (!string.IsNullOrEmpty(requestedUrl))
            {
                var page = _pagesService.GetByFriendlyUrl(requestedUrl);
                pageModel = new PageViewModel
                                {
                                    Content = page.Content,
                                    Title = page.Heading
                                };
            }
            else
            {
                pageModel = new PageViewModel {Title = "<h3>404. Page not Found</h3>"};
            }

            return View("PageView", pageModel);
        }
    }
}
